package com.mostromas.ess.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mostromas.ess.entities.Supplier;
import com.mostromas.ess.product.mapper.SupplierMapper;
import com.mostromas.ess.product.req.SupplierREQ;
import com.mostromas.ess.product.service.ISupplierService;
import com.mostromas.ess.util.base.Result;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {
    @Override
    public Result queryPage(SupplierREQ req) {

        QueryWrapper<Supplier> wrapper = new QueryWrapper<>();

        if(StringUtils.isNotEmpty(req.getName())){
            wrapper.like("name",req.getName());
        }
        if(StringUtils.isNotEmpty(req.getContact())){
            wrapper.like("contact",req.getContact());
        }
        if(StringUtils.isNotEmpty(req.getAddress())){
            wrapper.like("address",req.getAddress());
        }
        wrapper.orderByAsc("sort");

        IPage<Supplier> data = baseMapper.selectPage(req.getPage(),wrapper);
        return Result.ok(data);
    }
}
